<?php

namespace Rexzy\Base;

/**
 * 管理日志错误类
 * 
 * @since 0.0.1
 * @author Rex
 */
class Log {
    private $_filePath;
    
    public function __construct() {
        $dirPath = REXZY_ROOT . '/Data/log';
        if ( ! is_dir( $dirPath ) ) {
            mkdir( $dirPath );
        }
        $this->_filePath = $dirPath . '/logfile_' . date('Y-m-d') . '.txt';
        
        if ( !file_exists( $this->_filePath ) ) {
            @touch( $this->_filePath );
        }
    }
    
    /**
     * 写入错误
     * 
     * @param string $errorContent 错误描述
     */
    public function write( $errorContent, $output = false ) {
        $fp = @fopen( $this->_filePath, 'a' );
        @fwrite( $fp, $errorContent );
        @fclose( $fp );
        if ( $output ) {
            echo nl2br( $errorContent );
        }
    }
}
